using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cmc.Modbus.Base
{
    public class ReadDataBack
    {
        public string Ip { get; set; }
        public int Port { get; set; }

        public byte[] Datas { get; set; }

        public FunctionType FunctionType
        {
            get
            {
                if (ThisFunctionCode == FunctionCode.ReadHR || ThisFunctionCode == FunctionCode.WriteHR || ThisFunctionCode == FunctionCode.WriteHRs)
                {
                    return FunctionType.HoldingRegister;
                }
                else if (ThisFunctionCode == FunctionCode.ReadCS || ThisFunctionCode == FunctionCode.WriteCS || ThisFunctionCode == FunctionCode.WriteCSs)
                {
                    return FunctionType.CoilStatus;
                }
                else if (ThisFunctionCode == FunctionCode.ReadIS)
                {
                    return FunctionType.InputStatus;
                }
                else if (ThisFunctionCode == FunctionCode.ReadIR)
                {
                    return FunctionType.InputRegister;
                }

                return FunctionType.Error;
            }
        }

        public int Id { get; set; }
        public byte StationNumber { get; set; }

        public  int StartAddr { get; set; }

         public byte ThisFunctionCode { get; set; }


        public int Length { get; set; }

        public Dictionary<int, AddressReadValue> Addresses { get; set; } = new Dictionary<int, AddressReadValue>();


    }
}
